﻿#include "StackedSettingsDialog.h"
#include "ui_StackedSettingsWidget.h"
#include "settings/KVMManagerWidget.h"

#include <QDebug>

StackedSettingsDialog::StackedSettingsDialog(QWidget *parent) :
    BaseDialog(parent, QStringLiteral("系统设置")),
    ui(new Ui::StackedSettingsWidget)
{
    resize(1024, 768);

    QWidget* contentWidget = new QWidget(this);
    ui->setupUi(contentWidget);

    m_buttons =
    {
        ui->toolButton,
        ui->toolButton_2,
        ui->toolButton_3,
        ui->toolButton_4,
        ui->toolButton_5,
    };

    connect(ui->buttonGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled),
          [this](int id, bool checked)
    {
        if (!checked) return;

        // id默认从-1依次递减，如果手动调用addButton可以自由指定id
        int index = (id + 2) * -1;
        ui->stackedWidget->setCurrentIndex(index);
    });

    m_settingsFormList =
    {
        new KVMManagerWidget(contentWidget),
        new QWidget(contentWidget),
        new QWidget(contentWidget),
        new QWidget(contentWidget),
        new QWidget(contentWidget),
    };

    for (auto* form : m_settingsFormList)
    {
        ui->stackedWidget->addWidget(form);
    }

    // 默认选中第一页
    m_buttons[0]->setChecked(true);

    setContentWidget(contentWidget);
}

StackedSettingsDialog::~StackedSettingsDialog()
{
    delete ui;
}
